package 结构型模式.享元模式.图书馆借阅plus错误栈溢出;

import java.util.HashMap;

public class BookFactory {
    private HashMap<String, BookStyle> map;
    //在构造方法中进行初始化

    public BookFactory() {
        map=new HashMap<>();
        map.put("红楼梦",new Hongloumeng());
        map.put("三国演义",new Sanguoyanyi());
        map.put("西游记",new Xiyouji());
        map.put("水浒传",new Shuihuzhuan());
    }
    //提供一个饿汉式获取工厂类对象的方法
    private static BookFactory factory=new BookFactory();
    public static BookFactory getInstance(){
        return factory;
    }

    //根据书名获取页数对象
    public BookStyle getBook(String book){
        return map.get(book);
    }
}
